const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const timeCompare = (t1, t2) => {
  var time1 = t1.split(":")
  var time2 = t2.split(":")
  if (time1[0] == time2[0] && time1[1] == time2[1]) {// 时间相等
    return 0;
  } else if (time1[0] > time2[0] || (time1[0] == time2[0] && time1[1] > time2[1])) {// t1大 
    return 1;
  } else {// t2大
    return -1;
  }
}

module.exports = {
  formatTime: formatTime,
  timeCompare
}
